/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import demo_login.*;
import dao.Student;
import dao.StudentDaoJDBCImpl;
import demo_login.NewJFrame_add;
import demo_login.NewJFrame_delet;
import demo_login.NewJFrame_find;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;

/**
 *
 * @author C079
 */
public class MainFrame extends javax.swing.JFrame {

    public MainFrame() {
        initComponents();
        //jMenuItem2MousePressed(null);
        //MenuItem 菜单项
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu_select = new javax.swing.JMenu();
        jMenuItem_save = new javax.swing.JMenuItem();
        jMenuItem_exit = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu_edit = new javax.swing.JMenu();
        jMenu_find = new javax.swing.JMenu();
        jMenuItem_nameFind = new javax.swing.JMenuItem();
        jMenuItem_idFind = new javax.swing.JMenuItem();
        jMenuItem_add = new javax.swing.JMenuItem();
        jMenuItem_update = new javax.swing.JMenuItem();
        jMenuItem_delete = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu_help = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable2.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jLabel1.setFont(new java.awt.Font("宋体", 0, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("学生成绩信息表");

        jMenu_select.setText("选项");

        jMenuItem_save.setText("保存");
        jMenu_select.add(jMenuItem_save);

        jMenuItem_exit.setText("退出");
        jMenuItem_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_exitActionPerformed(evt);
            }
        });
        jMenu_select.add(jMenuItem_exit);

        jMenuItem2.setText("更新表格数据");
        jMenuItem2.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
                jMenuItem2MenuKeyPressed(evt);
            }
            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
            }
            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem2MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem2MousePressed(evt);
            }
        });
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu_select.add(jMenuItem2);

        jMenuItem5.setText("返回");
        jMenuItem5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem5MousePressed(evt);
            }
        });
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu_select.add(jMenuItem5);

        jMenuBar1.add(jMenu_select);

        jMenu_edit.setText("编辑");

        jMenu_find.setText("查找");

        jMenuItem_nameFind.setText("姓名");
        jMenuItem_nameFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_nameFindActionPerformed(evt);
            }
        });
        jMenu_find.add(jMenuItem_nameFind);

        jMenuItem_idFind.setText("学号");
        jMenuItem_idFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_idFindActionPerformed(evt);
            }
        });
        jMenu_find.add(jMenuItem_idFind);

        jMenu_edit.add(jMenu_find);

        jMenuItem_add.setText("添加");
        jMenuItem_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_addActionPerformed(evt);
            }
        });
        jMenu_edit.add(jMenuItem_add);

        jMenuItem_update.setText("修改");
        jMenuItem_update.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_updateActionPerformed(evt);
            }
        });
        jMenu_edit.add(jMenuItem_update);

        jMenuItem_delete.setText("删除");
        jMenuItem_delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_deleteActionPerformed(evt);
            }
        });
        jMenu_edit.add(jMenuItem_delete);
        jMenu_edit.add(jSeparator1);

        jMenuBar1.add(jMenu_edit);

        jMenu1.setText("统计分析");

        jMenuItem4.setText("柱状图分析");
        jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem4MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem4MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu_help.setText("帮助");

        jMenuItem1.setText("查看帮助");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem1MousePressed(evt);
            }
        });
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu_help.add(jMenuItem1);

        jMenuItem3.setText("关于");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem3MousePressed(evt);
            }
        });
       
        jMenu_help.add(jMenuItem3);

        jMenuBar1.add(jMenu_help);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
//退出菜单项 
    private void jMenuItem_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exitActionPerformed
        JOptionPane.showMessageDialog(null, "已退出");
        System.exit(0);//退出程序
    }//GEN-LAST:event_jMenuItem_exitActionPerformed

    private void jMenuItem_updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_updateActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem_updateActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        new NewJFrame_help().setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_addActionPerformed
        new NewJFrame_add().setVisible(true);
    }//GEN-LAST:event_jMenuItem_addActionPerformed

    private void jMenuItem_deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_deleteActionPerformed
        new NewJFrame_delet().setVisible(true);//新建了一个窗体，并显示
    }//GEN-LAST:event_jMenuItem_deleteActionPerformed

    private void jMenuItem_nameFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_nameFindActionPerformed
        NewJFrame_find nf_find = new NewJFrame_find();
        nf_find.setVisible(true);
        nf_find.setLl(ll);

    }//GEN-LAST:event_jMenuItem_nameFindActionPerformed

    private void jMenuItem_idFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_idFindActionPerformed
        new NewJFrame_find().setVisible(true);
    }//GEN-LAST:event_jMenuItem_idFindActionPerformed

    private void jMenuItem2MenuKeyPressed(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_jMenuItem2MenuKeyPressed
        // TODO add your handling code here:
        System.out.println("更新表格数据");
    }//GEN-LAST:event_jMenuItem2MenuKeyPressed

    private void jMenuItem2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MouseClicked
        // TODO add your handling code here:
        System.out.println("更新表格数据");
    }//GEN-LAST:event_jMenuItem2MouseClicked

    private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MousePressed
        // TODO add your handling code here:
        System.out.println("更新表格数据jMenuItem2MousePressed");
        String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
        Object[][] data = {
            {"Kathy", "Smith",
                "Snowboarding", new Integer(5), new Boolean(false)},
            {"John", "Doe",
                "Rowing", new Integer(3), new Boolean(true)},
            {"Sue", "Black",
                "Knitting", new Integer(2), new Boolean(false)},
            {"Jane", "White",
                "Speed reading", new Integer(20), new Boolean(true)},
            {"Joe", "Brown",
                "Pool", new Integer(10), new Boolean(false)}
        };

        Vector columnNamesStudent = new Vector();
        columnNamesStudent.add("学号");
        columnNamesStudent.add("姓名");
        columnNamesStudent.add("性别");
        columnNamesStudent.add("出生日期");
        columnNamesStudent.add("数学成绩");
        columnNamesStudent.add("Java成绩");
        columnNamesStudent.add("体育成绩");
        columnNamesStudent.add("总分");

        //StudentDaoJDBCImpl students=new StudentDaoJDBCImpl();
        Vector data2 = new Vector();

        //List<Student> ll=students.diplayAllStudent();
        if (ll == null) {
            ll = new StudentDaoJDBCImpl().diplayAllStudent();
        }
        for (int i = 0; i < ll.size(); i++) {
            Vector dataRow = new Vector();
            dataRow.add(ll.get(i).getId());
            dataRow.add(ll.get(i).getName());
            dataRow.add(ll.get(i).getGender());
            dataRow.add(ll.get(i).getBirthday());
            dataRow.add(Double.toString(ll.get(i).getScoreList().get(0).getScore()));
            dataRow.add(Double.toString(ll.get(i).getScoreList().get(1).getScore()));
            dataRow.add(Double.toString(ll.get(i).getScoreList().get(2).getScore()));
            //dataRow.add(Double.toString(ll.get(i).getTotalpoint()));
            dataRow.add(Double.toString(ll.get(i).getTotalpoint()));
            data2.add(dataRow);
        }
        JTable jTable3 = new JTable(data2, columnNamesStudent);

        jScrollPane2.setViewportView(jTable3);
        jTable3.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {//仅当鼠标单击时响应
                //得到选中的行列的索引值
                int r = jTable3.getSelectedRow();
                int c = jTable3.getSelectedColumn();
                //得到选中的单元格的值，表格中都是字符串
                Object value = jTable3.getValueAt(r, c);
                JPanelScore.main(ll.get(r));
                String info = r + "行" + c + "列值 : " + ll.get(r);
                javax.swing.JOptionPane.showMessageDialog(null, info);
            }
        });
    }//GEN-LAST:event_jMenuItem2MousePressed

    private void jMenuItem4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem4MouseClicked
        // TODO add your handling code here:
        System.out.println("柱状图数据分析 ");
    }//GEN-LAST:event_jMenuItem4MouseClicked

    private void jMenuItem4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem4MousePressed
        // TODO add your handling code here:
        System.out.println("柱状图数据分析 jMenuItem4MousePressed");
        new NewJFrame_About().setVisible(true);
    }//GEN-LAST:event_jMenuItem4MousePressed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem5MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem5MousePressed
        // TODO add your handling code here:
        this.setVisible(false);
        new JSelect().setVisible(true);
    }//GEN-LAST:event_jMenuItem5MousePressed


    private void jMenuItem3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MousePressed
        // TODO add your handling code here:
         
    }//GEN-LAST:event_jMenuItem3MousePressed

    private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1MousePressed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    public static List<Student> ll;

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        StudentDaoJDBCImpl students = new StudentDaoJDBCImpl();
        ll = students.diplayAllStudent();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem_add;
    private javax.swing.JMenuItem jMenuItem_delete;
    private javax.swing.JMenuItem jMenuItem_exit;
    private javax.swing.JMenuItem jMenuItem_idFind;
    private javax.swing.JMenuItem jMenuItem_nameFind;
    private javax.swing.JMenuItem jMenuItem_save;
    private javax.swing.JMenuItem jMenuItem_update;
    private javax.swing.JMenu jMenu_edit;
    private javax.swing.JMenu jMenu_find;
    private javax.swing.JMenu jMenu_help;
    private javax.swing.JMenu jMenu_select;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTable jTable2;
    // End of variables declaration//GEN-END:variables
}
